#pragma once

//#include "ModelViewDefines.h"
//#include "ModelIndex.h"
//#include "Var.h"

namespace DuiLib
{

	// QAbstractItemModel
	class UILIB_API CAbstractItemModel
	{
	public Dui_Signals:
		sigslot::Signal<const CModelIndex&, const CVar&, const CVar&> dataChanged;
		sigslot::Signal<int, Orientation, const CVar&, const CVar&> headerDataChanged;

		sigslot::Signal<int, int, const CModelIndex&> rowsBeforeInsert;
		sigslot::Signal<int, int, const CModelIndex&> rowsInserted;

		sigslot::Signal<int, int, const CModelIndex&> rowsBeforeRemove;
		sigslot::Signal<int, int, const CModelIndex&> rowsRemoved;

		sigslot::Signal<int, int, const CModelIndex&> columnsBeforeInsert;
		sigslot::Signal<int, int, const CModelIndex&> columnsInserted;

		sigslot::Signal<int, int, const CModelIndex&> columnsBeforeRemove;
		sigslot::Signal<int, int, const CModelIndex&> columnsRemoved;

		sigslot::Signal<int> allRemoved;

	public:
		CAbstractItemModel() {};
		virtual ~CAbstractItemModel() {};

		virtual bool hasIndex(int row, int col, const CModelIndex& parent = CModelIndex()) const = 0;
		virtual CModelIndex index(int row, int col, const CModelIndex& parent = CModelIndex()) const = 0;
		virtual CModelIndex sibling(int row, int col, const CModelIndex& idx) const = 0;

		virtual CModelIndex parent(const CModelIndex& child) const = 0;
		virtual bool hasChild(const CModelIndex& parent = CModelIndex()) const = 0;

		virtual int rowCount(const CModelIndex& parent = CModelIndex()) const = 0;
		virtual int columnCount(const CModelIndex& parent = CModelIndex()) const = 0;

		virtual CVar data(const CModelIndex& index) const = 0;
		virtual bool setData(const CModelIndex& index, const CVar& var) = 0;

		virtual CVar headerData(int section, Orientation orient) const;
		virtual bool setHeaderData(int section, Orientation orient, const CVar& var) const;

		virtual bool insertRows(int row, int count, const CModelIndex& parent = CModelIndex());
		virtual bool removeRows(int row, int count, const CModelIndex& parent = CModelIndex());

		virtual bool insertColumns(int column, int count, const CModelIndex& parent = CModelIndex());
		virtual bool removeColumns(int column, int count, const CModelIndex& parent = CModelIndex());

		virtual bool removeAll();

	protected:
		inline CModelIndex createIndex(int row, int col, const void* ptr = NULL) const;
	};

}